package com.twu.biblioteca;

import com.twu.biblioteca.Libraries.UserAccountLibrary;

import java.util.Scanner;

public class Session {

    private UserAccountLibrary accounts = new UserAccountLibrary();

    public boolean login(UserAccount sessionUser, int attempts) {

        if(sessionUser.isActive())
            return true;
        else {

            while(attempts > 0) {

                UserAccount user = new UserAccount( getUserNameInput() , getPasswordInput());

                if (accounts.validateUsernamePassword(user)) {
                    sessionUser.activate(user);
                    return true;

                }
                attempts--;
            }
        }

        return false;

    }
    public String getUserNameInput() {
        Scanner sc = new Scanner(System.in);
        System.out.print("Username ? : ");
        return sc.next();


    }

    public String getPasswordInput() {

        Scanner sc = new Scanner(System.in);
        System.out.print("Password ? :");
        return sc.next();

    }


}
